package schedule

import (
	"fmt"
)

var arr = []int{}
var isClose = false

func producer(ch chan<- int) {

	for i := 0; i < 4; i++ {
		ch <- i
	}
	// close(ch)
	// if isClose == true {
	// 	close(ch)
	// } else {
	// 	isClose = true
	// }
}
func consumer(ch <-chan int) {

	for {
		i, ok := <-ch
		if ok == false {
			fmt.Println(ok)
			break
		}
		arr = append(arr, i)
	}

}

func test() {
	fmt.Println("test")
	ch := make(chan int, 2)
	go producer(ch)
	// go producer(ch)
	// go producer(ch)
	// go consumer(ch)
	// go consumer(ch)
	// time.Sleep(time.Second)
	// fmt.Println(arr)
	for {
		select {
		case a, ok := <-ch:
			fmt.Println(a, ok)
		}
	}

}
